Skip to content

Conversation

prigiattiperrut
Copy link
Contributor

Proposed changes

Updated documentation to reflect the possibility of running multiple versions of Analytics.js (e.g., a snippet version and an npm version) with different write keys in the same environment.

Merge timing

ASAP once approved

Related issues (optional)

segmentio/analytics-next#1127

https://twilio.slack.com/archives/C9Z93GW76/p1725380202861859

Note that you *cannot* load Analytics.js twice on the same page, even if you're using different write keys. You might encounter `Uncaught RangeError: Maximum call stack size exceeded`. You can conditionally set the write key based on an environment variable.
### Analytics.js Snippet Loaded More Than Once

It is not possible to load the Analytics.js snippet twice on the same page, even if different write keys are used. Doing so often results in errors like `Uncaught RangeError: Maximum call stack size exceeded`. However, you can conditionally set the write key based on an environment variable:
Copy link
Contributor

@silesky silesky Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested, but it "should" be possible to use two snippets in the same page --just change one snippet to use the another variable name (eg analytics1 and analytics2).

The new snippet makes it super easy to rename the analytics variable to something else.

Worth testing, there were a lot of assumptions built into the library that there would only be one snippet, but we've gradually refactored them out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@forstisabella
Copy link
Contributor

hi @prigiattiperrut and @silesky - any movement on this PR? Should we close this PR?

@forstisabella forstisabella requested a review from silesky June 30, 2025 15:26
silesky
silesky previously approved these changes Jun 30, 2025
@forstisabella forstisabella merged commit 93566d9 into develop Jun 30, 2025
4 checks passed
@forstisabella forstisabella deleted the prigiattiperrut-patch-4 branch June 30, 2025 15:54
Copy link
Contributor

Thank you for your contribution! Your pull request is merged, but may take a day or two to appear on the site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants